package com.sc.syllabus.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.sc.syllabus.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liushuanglong on 2017/9/30.
 */

public class RecyclerActivity extends Activity {

    private RecyclerView mRecyclerView;
    private MyAdapter mMyAdapter;
    private List<String> mList;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler);

        //RecyclerView三部曲+LayoutManager         
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        initData();
        mMyAdapter = new MyAdapter(mList);
        mRecyclerView.setAdapter(mMyAdapter);

        //为RecyclerView添加HeaderView和FooterView   
        setHeaderView(mRecyclerView);
        setFooterView(mRecyclerView);
    }

    private void initData() {
        mList = new ArrayList<String>();
        for (int i = 0; i < 20; i++) {
            mList.add("item" + i);
        }
    }

    private void setHeaderView(RecyclerView view) {
        View header = LayoutInflater.from(this).inflate(R.layout.header, view, false);
        mMyAdapter.setHeaderView(header);
    }

    private void setFooterView(RecyclerView view) {
        View footer = LayoutInflater.from(this).inflate(R.layout.header, view, false);
        mMyAdapter.setFooterView(footer);
    }

    public static void actionStart(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, RecyclerActivity.class);
        context.startActivity(intent);
    }
}
